/*!
 * C2Rust 智能转换工具库
 * 
 * 基于LLM的C到Rust代码转换系统的核心库
 */

// 核心模块
pub mod code_splitter;
pub mod config;
pub mod llm;
pub mod file_scanner;
pub mod llm_converter;
pub mod project_builder;
pub mod smart_fixer;

// 重新导出主要类型
pub use code_splitter::CodeSplitter;
pub use config::Config;
pub use llm::{LlmAssistant, FileAnalysis};
pub use file_scanner::{FileScanner, CFile, ScanResult};
pub use llm_converter::{LlmConverter, RustProject, RustModule};
pub use project_builder::ProjectBuilder;

/// 库版本
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// 简化的转换API
pub mod api {
    use super::*;
    use anyhow::Result;
    use std::path::Path;
    
    /// 一站式转换函数
    pub async fn convert_c_project(
        input_path: &Path,
        output_path: &Path,
        project_name: &str,
        config: Config,
    ) -> Result<()> {
        // 扫描文件
        let scanner = FileScanner::new();
        let scan_result = if input_path.is_file() {
            let c_file = scanner.scan_single_file(input_path)?;
            ScanResult {
                source_files: vec![c_file],
                total_lines: 0,
            }
        } else {
            scanner.scan_project(input_path)?
        };
        
        // LLM转换
        let llm_assistant = if let Some(llm_config) = config.llm {
            LlmAssistant::new(llm_config)?
        } else {
            return Err(anyhow::anyhow!("需要配置LLM设置"));
        };
        
        let mut converter = LlmConverter::new(llm_assistant);
        let rust_project = converter.convert_project(scan_result, project_name).await?;
        
        // 构建项目
        let builder = ProjectBuilder::new();
        builder.build_project(&rust_project, output_path)?;
        builder.validate_project(output_path)?;
        
        Ok(())
    }
}